Conditional Control Statements || IF-Else Statement

Conditional Control Statements || IF-Else Statement

Conditional Control Statements || IF-Else Statement

IF Else Statement :-

The if-else statement is an extension of simple-if statement. The general form is

Syntax :-

if(condition)
{
True statement
}
else
{
False Statement
}

Flow Chart :-

Program 1 :

Write a program to check whether the given age is eligible for vote or not.

#include<stdio.h>
#include<conio.h>
void main()
       {
             int age;
             clrscr();
             printf(“enter your age:”);
             scanf(“%d”,&age);
             If(age>18)

            printf(“you are eligible for vote”);
             else
             printf(“you are not eligible for vote”);
             getch();

}

   

Output :-

Enter your age: 24
you are eligible for vote
Enter your age: 13
you are not eligible for vote

Program 2 :

Write a program to check whether the given number is Positive Number or Negative Number.

#include<stdio.h>
#include<conio.h>
void main()
       {
             int no;
             clrscr();
             printf(“enter any number:”);
             scanf(“%d”,&no);
             If(no>0)

            printf(“it is a Positive Number”); or printf(“%d is a Positive Number”,no);
             else
             printf(“it is a Negative Number”); or printf(“%d is a Negative Number”,no);
             getch();

}

Output :-

Enter any Number : 7
it is a Positive Number (or) 7 is a Positive Number
Enter any Number : -13
it is a Negative Number (or) -13 is a Positive Number

Extra Program Outputs :-

Output 1:-

Enter your age: 17
you are teenager
Enter your age:23
you are not teenager

Output 2:-

Enter any two Number : 17
25
Big Value is : 25
Enter any two Number : 11
5
Big Value is : 11

durgaprasad

leave a comment

Create Account



Log In Your Account